package org.ht.database;

import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;

import javax.imageio.ImageIO;

public class BlobToImageHelper {
	private Image img;

	public Image writeBlobToImage(Object originData) throws SQLException,
			IOException {
		// 读取Blob对象
		byte[] blob = (byte[]) originData;

		// Blob对象转化为InputStream流
		java.io.InputStream inputStream = new ByteArrayInputStream(blob);

		img = ImageIO.read(inputStream);

		return img;
	}

	public void writeBlobToFile(Object originData, String fileName)
			throws IOException {
		byte[] blob = (byte[]) originData;
	    FileOutputStream fileOuputStream = 
                  new FileOutputStream(fileName); 
	    fileOuputStream.write(blob);
	    fileOuputStream.close();
	}
}
